package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Task;
import com.qidianit.mes.pro.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ Description:
 * @ Author:WuJingLei
 * @ Date: 2025/9/24 -16:58
 */
@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    @PostMapping("/add")
    public Result add(@RequestBody Task task){
        return taskService.addTask(task);
    }

    @GetMapping("/list")   // task/list?xxx=xx&xxx=xxx
    public Result<List<Task>> queryList(Task task){
        return taskService.queryTaskList(task);
    }

    @GetMapping("/get")
    public Result queryByCode( String code){
        return taskService.getByTaskCode(code);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Task task){
        return  taskService.updateTask(task);
    }

    @DeleteMapping("/delete/{id}") //  task/delet?id=12
    public Result delete(@PathVariable Long id){
        return taskService.deleteTask(id);
    }

    @DeleteMapping("/batchDelete")
    public Result delete(Long[] id){
        return taskService.batchDelete(id);
    }

    @GetMapping("/page")   // task/list?xxx=xx&xxx=xxx
    public Result<PageInfo<Task>> queryPage(Task task,
                                            @RequestParam(defaultValue = "1")int pageNum,
                                            @RequestParam(defaultValue = "10")int size){
        return taskService.queryPage(task,pageNum,size);
    }
}
